<?php

	/**
	 * @see Zend_Controller_Request_Http
	 */
	require_once 'Zend/Controller/Request/Http.php';
	
	
	class Bike_Controller_Request_Http extends Zend_Controller_Request_Http
	{        const TYPE_POST = 'POST';
        const TYPE_GET = 'GET';
        const TYPE_REQUEST = 'REQUEST';

        protected $_cleanData = array();

        protected function getCleanData($Type = self::TYPE_POST)
        {        	switch($Type)
        	{        		case self::TYPE_GET: 		$Data = $_GET; break;
        		case self::TYPE_REQUEST: 	$Data = $_REQUEST; break;
        		case self::TYPE_POST:
        		default: 					$Data = $_POST; $Type = self::TYPE_POST;
        	}
        	if(!isset($this->_cleanData[$Type]))
        	{
	        	$suffix = Bike_Js_Ext::getInputElSuffix();
		        $len = strlen($suffix);
		        if($len)
		        {
			        foreach($Data as $key => $value)
			        {
			        	if(substr($key, -$len) == $suffix)
			        	{
			        		$cleanKey = substr($key, 0, -$len);
			        		if(!isset($Data[$cleanKey]))
			        		{
			        			$Data[$cleanKey] = $value;
			        			unset($Data[$key]);
			        		}
			        	}
			        }
				}
				$this->_cleanData[$Type] = $Data;
			}
			return $this->_cleanData[$Type];
        }

        public function __call($MethodName, array $Args=Null)
        {        	if(substr($MethodName,0,8) == 'getClean')
        	{        		$Type = strtoupper(substr($MethodName,8));
        		array_unshift($Args, $Type);
        		return call_user_func_array(array($this, 'getClean'), $Args);
        	}
        }

        protected function getClean($Type, $Key = null, $Default = null)
	    {
	        switch($Type)
        	{
        		case self::TYPE_GET: 		break;
        		case self::TYPE_REQUEST: 	break;
        		case self::TYPE_POST: 		break;
        		default: 					Throw new Zend_Controller_Request_Exception('Can not get clean data for type: '.$Type);
        	}
	        $Data = $this->getCleanData($Type);
	        if(is_null($Key))
	        {
            	return $Data;
        	}
        	return (isset($Data[$Key])) ? $Data[$Key] : $Default;
	    }
	}

?>